﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class SSkillInput : MonoBehaviour,IPointerDownHandler, IPointerUpHandler
{
	private Vector2 m_PointerPosition;

	private int m_PointerID;

	private Vector2 m_LastStayPos;
	private Vector3 m_LastOffsetRatio;
	void Start () {
		
	}
	/// <summary>
	/// ???????
	/// </summary>
	/// <returns></returns>
	public Vector3 GetPreviewWorldOffset()
	{
		//处理Sensitive.....
		
		var screenSize = Mathf.Max(Screen.width, Screen.height);
		//var limitMin = m_RadiusLimitMin * screenSize;

		//var offsetRatio = deltaRatio.ExpandZ().SwapYZ();
		
		RefreshTouchPosition();

		var delta = m_PointerPosition - m_LastStayPos;
		Debug.Log("skill_delta="+delta);
		Vector3 offsetRatio = new Vector3(0, 0, 0);
		//if (type == AttackArea.AreaType.Circle)
//		{
//			var lerp = Vector3.ClampMagnitude(offsetRatio - m_LastOffsetRatio, Mathf.Lerp(GameSettings.SensitivityMinSpeed,GameSettings.SensitivityMaxSpeed,sensitivity) * Time.deltaTime);
//			offsetRatio = m_LastOffsetRatio + lerp;
//		}
		//else
//		{
//			if (!m_LastOffsetRatio.Equals(Vector3.zero))
//			{
//				var angle = Mathf.Lerp(GameSettings.SensitivityMinAngleSpeed, GameSettings.SensitivityMaxAngleSpeed, sensitivity) * Time.deltaTime;
//				Vector3 cross = Vector3.Cross(m_LastOffsetRatio.SwapYZ(), offsetRatio.SwapYZ());
//				var _angle = Vector3.Angle(offsetRatio, m_LastOffsetRatio);
//				angle = Mathf.Min(angle, _angle);
//				if (_angle < angle)
//				{
//					angle = _angle;
//				}
//				offsetRatio = Quaternion.AngleAxis(cross.z > 0 ? -angle : angle, new Vector3(0,1,0)) * m_LastOffsetRatio ;
//			}
//		}
//
//		m_LastOffsetRatio = offsetRatio;
		return offsetRatio;
	}

	void RefreshTouchPosition()
	{
		var touchCount = Input.touchCount;
		if (!Application.isMobilePlatform)
		{
			m_PointerPosition = Input.mousePosition;
		}
		else if (touchCount > 0)
		{
			for (int i = 0; i < touchCount; ++i)
			{
				var touch = Input.GetTouch(i);
				if (touch.fingerId == m_PointerID)
				{
					m_PointerPosition = touch.position;
					break;
				}
			}
		}
	}

	public void OnPointerDown(PointerEventData eventData)
	{
		m_LastStayPos = eventData.position;
	}

	public void OnPointerUp(PointerEventData eventData)
	{
		
	}
}
